from domain.player import Player
from namegen import RussianGrammar, SpanishGrammar

from random import sample, choice


class Team(object):

    def __init__(self, name, players=None):
        self.name = name
        if players is None:
            PLAYER_NUMBER = 11
            numeration = _create_numeration(PLAYER_NUMBER)
            n = choice((RussianGrammar(), SpanishGrammar()))
            p = [(numeration[i], Player(nationality=n)) for i in xrange(PLAYER_NUMBER)]
        else:
            PLAYER_NUMBER = len(players)
            numeration = _create_numeration(PLAYER_NUMBER)
            p = [(numeration[i], p) for p in players]
        self.players = p

def _create_numeration(player_number):
    numbers = range(2, player_number+1)
    numeration = [1] + sample(numbers, len(numbers))
    return numeration
